fix(openai oauth): drop item_reference + stored-item id refs on OAuth path#2523
Open
yetone wants to merge 1 commit into
Open
fix(openai oauth): drop item_reference + stored-item id refs on OAuth path#2523yetone wants to merge 1 commit into
yetone wants to merge 1 commit into
Conversation
… path ChatGPT's internal /v1/responses backend rejects any item_reference (or any other item carrying an `id` from a prior turn) with HTTP 404: "Item with id '<fc_*|rs_*|...>' not found. Items are not persisted when `store` is set to false. Try again with `store` set to true, or remove this item from your input." We force `store=false` on OAuth (line ~138, and again in normalizeOpenAIPassthroughOAuthBody — line ~5828), so by construction upstream never has any persisted item to reference. Every continuation request was therefore guaranteed to 404. How we got here: 70eaa45 ("修复工具续链校验与存储策略") tried to fix continuation by forcing store=true on continuation turns AND preserving item_reference items in the input. 3663951 reverted the store=true half the next day after upstream returned "Store must be set to false", but left the preserve-references half in place. The two halves were load-bearing for each other; with only one of them, every continuation request 404s. Fix: pass PreserveReferences=false unconditionally on the OAuth path. The function_call + matching function_call_output items inlined in the same request body already carry the full continuation context — that's the standard Responses-API continuation shape and upstream accepts it fine without any stored-item references. Drop the now-vestigial `needsToolContinuation` variable (it was only read by the line we're changing). Update the three tests that locked in the broken intermediate behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every continuation request (i.e. any
/v1/responsesrequest withfunction_call_outputitems, oritem_referenceitems, ininput) routed through the OAuth path is currently guaranteed to fail with HTTP 502, masking an upstream HTTP 404:In production this manifests as a 100% failure rate for any client that uses tool-calling continuation through OAuth — no successful turn after the first one is ever possible.
Root cause
The OAuth path forces
store=falseon the upstream request — both inapplyCodexOAuthTransform(`openai_codex_transform.go` around line 138) and again as a belt-and-braces in `normalizeOpenAIPassthroughOAuthBody` (`openai_gateway_service.go` around line 5828). Withstore=false, ChatGPT's internal Responses backend never persists any item, so any `item_reference` (and any other item carrying an `id` from a prior turn) is guaranteed to 404.How we got into this state:
So every continuation request now goes upstream with `store=false` plus preserved `item_reference` items / `id` fields → guaranteed 404 → 502 to the client.
Fix
Pass `PreserveReferences: false` unconditionally on the OAuth path. The function_call + matching function_call_output items inlined in the same request body already carry the full continuation context — that's the standard Responses-API continuation shape and upstream accepts it without any stored-item references.
Drop the now-vestigial `needsToolContinuation` local (it was only read by the line we're changing).
Update the three tests that had been written to lock in 70eaa45's intermediate behavior (`TestApplyCodexOAuthTransform_ToolContinuationPreservesInput`, `...PreservesNativeMessageAndReasoningIDs`, `...NormalizesToolReferenceIDsOnly`) so they assert the corrected behavior:
Verification (production)
Deployed this patch on top of `cumora-prod` in our fork and rolled it to GKE. Sampled `/v1/responses` status codes on the OAuth path before and after a probe wake of 4 agent pods:
The original failure mode is fully eliminated. The remaining 502s carry a different upstream message and trace to a separate client-side bug unrelated to this PR.
Test plan